package com.manor.main.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;

import com.flyco.tablayout.SlidingTabLayout;
import com.manor.common.activity.AbsActivity;
import com.manor.common.custom.MyViewPager;
import com.manor.main.R;
import com.manor.main.adapter.RankingListPagerAdapter;

import androidx.fragment.app.FragmentManager;
import androidx.viewpager.widget.ViewPager;

/**
 * 排行版、魅力版
 */
public class RankingListActivity extends AbsActivity   implements ViewPager.OnPageChangeListener{
    private SlidingTabLayout mTabLayout;
    private MyViewPager mViewPager;

    RankingListPagerAdapter rankingListPagerAdapter;

    public static void forward(Context context) {
        Intent intent = new Intent(context, RankingListActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
       return R.layout.activity_ranking_list;
    }

    @Override
    protected void main() {
        super.main();
        initView();
        setAdapter();

    }



    private void setAdapter() {
        FragmentManager supportFragmentManager = getSupportFragmentManager();
        mViewPager.setOffscreenPageLimit(1);
        rankingListPagerAdapter = new RankingListPagerAdapter(supportFragmentManager, RankingListActivity.this);
        mViewPager.setAdapter(rankingListPagerAdapter);
        mViewPager.setCurrentItem(0);
        mTabLayout.setViewPager(mViewPager);
        mViewPager.addOnPageChangeListener(RankingListActivity.this);

        mTabLayout.getTitleView(0).setTextSize(17f);
        mTabLayout.getTitleView(0).setTypeface(Typeface.DEFAULT_BOLD);

    }


    @Override
    public void onPageScrolled(int i, float v, int i1) {

    }

    @Override
    public void onPageSelected(int position) {

        if (position == 0) {
            mTabLayout.setTextsize(17f);
            mTabLayout.getTitleView(0).setTypeface(Typeface.DEFAULT_BOLD);

            mTabLayout.getTitleView(1).setTextSize(14f);
            mTabLayout.getTitleView(1).setTypeface(Typeface.DEFAULT);
        } else if (position == 1) {
            mTabLayout.setTextsize(17f);
            mTabLayout.getTitleView(1).setTypeface(Typeface.DEFAULT_BOLD);

            mTabLayout.getTitleView(0).setTextSize(14f);
            mTabLayout.getTitleView(0).setTypeface(Typeface.DEFAULT);

        }
    }

    @Override
    public void onPageScrollStateChanged(int i) {

    }

    private void initView() {
        mTabLayout = (SlidingTabLayout) findViewById(R.id.tab_layout);
        mViewPager = (MyViewPager) findViewById(R.id.viewPager);
    }
}
